// 配置路由
import 'package:asperm/pages/buy_page.dart';
import 'package:asperm/pages/forget_password_page.dart';
import 'package:asperm/pages/history_page.dart';
import 'package:asperm/pages/login_page.dart';
import 'package:asperm/pages/my_page.dart';
import 'package:asperm/pages/sign_up_page.dart';
import 'package:asperm/pages/start_testing_page.dart';
import 'package:asperm/views/testing_steps_widget.dart';
import 'package:asperm/pages/tips_page.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

import '../pages/report_page.dart';
import '../pages/testing_steps_page.dart';
import '../pages/home_page.dart';


final routes = {
  '/': (context, {arguments}) => HomePage(),
  '/login': (context, {arguments}) => LoginPage(),
  '/tips_page': (context, {arguments}) => TipsPage(),
  '/history_page': (context) => HistoryPage(),
  '/buy_page': (context) => BuyPage(),
  '/my_page': (context) => MyPage(),
  '/start_testing_page': (context) => StartTestingPage(),
  '/testing_steps_page': (context) => Testing_Steps_Page(),
  '/sign_up_page': (context) => SignUpPage(),
  '/forget_password_page': (context) => ForgetPasswordPage(),
  '/report_page': (context, {arguments}) => ReportPage(result: arguments),
};

//固定写法
var onGenerateRoute = (RouteSettings settings) {
  // 统一处理
  final String? name = settings.name;
  final Function pageContentBuilder = routes[name] as Function;

  if (pageContentBuilder != null) {
    if (settings.arguments != null) {

      // final Route route = MaterialPageRoute(
      //     builder: (context) =>
      //         pageContentBuilder(context, arguments: settings.arguments));

      final Route route = PageRouteBuilder(
        pageBuilder: (context, __, ___) => pageContentBuilder(context, arguments: settings.arguments),
        transitionsBuilder: (_, anim, __, child) =>
            SlideTransition(position: Tween(begin: Offset(1, 0), end: Offset.zero).animate(CurvedAnimation(
              parent: anim,
              curve: Curves.easeOut,
            ),), child: child),
        transitionDuration:  Duration(milliseconds: 300),
      );

      return route;
    } else {
      final Route route =
      MaterialPageRoute(builder: (context) => pageContentBuilder(context));

      // final Route route = PageRouteBuilder(
      //   pageBuilder: (context, __, ___) => pageContentBuilder(context),
      //   transitionsBuilder: (_, anim, __, child) =>
      //       SlideTransition(position: Tween(begin: Offset(1, 0), end: Offset.zero).animate(CurvedAnimation(
      //         parent: anim,
      //         curve: Curves.easeOut,
      //       ),), child: child),
      //   transitionDuration:  Duration(milliseconds: 300),
      // );

      return route;
    }
  }
};
